const user = {
    namespaced: true,
    state: {
        userInfo: function() {
            try {
                return JSON.parse(window.sessionStorage.getItem("userInfo")) || { error: 'asdas' }
            } catch (error) {
                console.log(error)
                return { error: 'asdas' }

            }
        }()
    },
    mutations: {
        setUserInfo(state, data) {
            //用于收集合并 零散的 用户信息
            var storeData = Object.assign(state.userInfo, {...data })
            state.userInfo = storeData;
            try {
                window.sessionStorage.setItem('userInfo', JSON.stringify(storeData))
            } catch (error) {
                console.log(error)
            }
        }
    },
    actions: {
        async login({ commit, }, data) {
            let loginData = await $api.login({...data });
            var userinfo = {...loginData.data, ...data };
            commit("setUserInfo", userinfo);
            commit("route/ROUTE_CHANGED", { to: { path: "/register" } }, { root: true });
        }
    }
}
export default user;